<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.blurry" clearable size="small" placeholder="模糊搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select
          v-model="query.bisSnryYbssqx"
          clearable
          size="small"
          placeholder="医保所属区县"
          class="filter-item"
          style="width: 150px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in dict.ccs"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="660px">
        <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="100px">
          <el-form-item label="姓名" prop="bisSnryXm">
            <el-input v-model="form.bisSnryXm" style="width: 180px;" />
          </el-form-item>
          <el-form-item label="性别" prop="bisSnryXb">
            <el-select v-model="form.bisSnryXb" filterable placeholder="请选择" style="width: 180px;">
              <el-option
                v-for="item in dict.xb"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="身份证" prop="bisSnrySfz">
            <el-input v-model="form.bisSnrySfz" style="width: 180px;" />
          </el-form-item>
          <el-form-item label="联系电话" prop="bisSnryLxdh">
            <el-input v-model="form.bisSnryLxdh" style="width: 180px;" />
          </el-form-item>
          <el-form-item label="监护人姓名" prop="bisSnryJhrxm">
            <el-input v-model="form.bisSnryJhrxm" style="width: 180px;" />
          </el-form-item>
          <el-form-item label="监护人电话" prop="bisSnryJhrdh">
            <el-input v-model="form.bisSnryJhrdh" style="width: 180px;" />
          </el-form-item>
          <el-form-item label="与失能人员关系" prop="bisSnryGx">
            <el-select v-model="form.bisSnryGx" filterable placeholder="请选择" style="width: 180px;">
              <el-option
                v-for="item in dict.yjsgx"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="医保所属区县" prop="bisSnryYbssqx">
            <el-select v-model="form.bisSnryYbssqx" filterable placeholder="请选择" style="width: 180px;">
              <el-option
                v-for="item in dict.ccs"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="申请原因">
            <el-input v-model="form.bisSnrySqyy" :rows="3" type="textarea" style="width: 470px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="bisSnryXm" label="姓名" align="center" />
        <el-table-column prop="bisSnryXb" label="性别" align="center">
          <template slot-scope="scope">
            {{ dict.label.xb[scope.row.bisSnryXb] }}
          </template>
        </el-table-column>
        <el-table-column prop="bisSnrySfz" label="身份证" align="center" />
        <el-table-column prop="bisSnryLxdh" label="联系电话" align="center" />
        <el-table-column prop="bisSnryJhrxm" label="监护人姓名" align="center" />
        <el-table-column prop="bisSnryJhrdh" label="监护人电话" align="center" />
        <el-table-column prop="bisSnryGx" label="与失能人员关系" align="center">
          <template slot-scope="scope">
            {{ dict.label.yjsgx[scope.row.bisSnryGx] }}
          </template>
        </el-table-column>
        <el-table-column v-if="checkPer(['admin','snry:edit','snry:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudSnry from '@/api/business/snry'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { bisSnryId: null, bisSnryHljgId: null, bisSnryXm: null, bisSnryXb: null, bisSnrySfz: null, bisSnryLxdh: null, bisSnryHldzSsqx: null, bisSnryHldzXxdz: null, bisSnryHldz: null, bisSnryJhrxm: null, bisSnryJhrdh: null, bisSnryGx: null, bisSnryYbssqx: null, bisSnrySqyy: null, ywlx: null, lrr: null, lrrxm: null, lrbm: null, lrbmmc: null, lrsj: null, gxr: null, gxrxm: null, gxbm: null, gxbmmc: null, gxsj: null, sfyx: null, bz: null }
export default {
  name: 'Snry',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['xb', 'yjsgx', 'ccs'],
  cruds() {
    return CRUD({ title: '失能人员', url: 'api/snry', idField: 'bisSnryId', sort: 'bisSnryId,desc', crudMethod: { ...crudSnry }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'snry:add'],
        edit: ['admin', 'snry:edit'],
        del: ['admin', 'snry:del']
      },
      rules: {
        bisSnryXm: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        bisSnryXb: [
          { required: true, message: '性别不能为空', trigger: 'blur' }
        ],
        bisSnrySfz: [
          { required: true, message: '身份证不能为空', trigger: 'blur' }
        ],
        bisSnryLxdh: [
          { required: true, message: '联系电话不能为空', trigger: 'blur' }
        ],
        bisSnryJhrxm: [
          { required: true, message: '监护人姓名不能为空', trigger: 'blur' }
        ],
        bisSnryJhrdh: [
          { required: true, message: '监护人电话不能为空', trigger: 'blur' }
        ],
        bisSnryGx: [
          { required: true, message: '与失能人员关系不能为空', trigger: 'blur' }
        ],
        bisSnryYbssqx: [
          { required: true, message: '医保所属区县不能为空', trigger: 'blur' }
        ]
      }}
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
